﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PPAP.BO;


namespace PPAP.Web.Part
{
    public partial class PPAPTasks : PageBase
    {
        PPARBO bo = new PPARBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadData();
            }
        }

        protected void AspNetPager2_PageChanged(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            DataTable dt = null;
            if (CurrentUser.UnitId == "0" || CurrentUser.UnitId == "99")
            {
                if (CurrentUser.UnitId == "0")
                    dt = bo.GetListForSupplier2(CurrentUser.UnitName).Tables[0];
                else if (CurrentUser.UnitId == "99")
                    dt = bo.GetListForSupplier3(CurrentUser.Id).Tables[0];
                dt.Columns.Add("pt");
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["planedppardate"].ToString() != "")
                        dr["pt"] = DateTime.Parse(dr["planedppardate"].ToString()).ToString("yyyy-MM-dd");
                }
                AspNetPager2.RecordCount = dt.Rows.Count;
                dgList.DataSource = GetPageTable(dt, AspNetPager2.PageSize, AspNetPager2.CurrentPageIndex);
                this.dgList.DataBind();
            }
        }

        protected override void SkinControl()
        {
            
        }

        public static DataTable GetPageTable(DataTable dt, int pageSize, int pageIndex)
        {
            if (dt != null)
            {
                DataTable dt1 = new DataTable();

                int pageEnd = pageIndex * pageSize;
                int pagebegin = (pageIndex - 1) * pageSize;


                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    dt1.Columns.Add(new DataColumn(dt.Columns[i].ColumnName));
                }

                for (int i = pagebegin; i < pageEnd; i++)
                {
                    if (i < dt.Rows.Count)
                    {
                        dt1.ImportRow(dt.Rows[i]);
                    }

                }
                return dt1;
            }
            else
                return null;
        }

        //protected void AspNetPager2_PageChanged(object sender, EventArgs e)
        //{
        //    AspNetPager2.RecordCount = bo.GetListForSupplier(CurrentUser.UnitName).Tables[0].Rows.Count;
        //    dgList.DataSource = GetPageTable(bo.GetListForSupplier(CurrentUser.UnitName).Tables[0], AspNetPager2.PageSize, AspNetPager2.CurrentPageIndex);
        //    dgList.DataBind();
        //}


        //状态显示
        public string ShowAuditStatus(string Status)
        {
            string result = "";
            result = "<span style='color:red'>已提交</span>";

            switch (Status.ToLower())
            {
                case "0":
                    result = "<span style='color:blue'>Allocated</span>";
                    break;
                case "1":
                    result = "<span style='color:red'>Created</span>";
                    break;
                case "2":
                    result = "<span style='color:red'>Submitted</span>";
                    break;
                case "3":
                    result = "<span style='color:red'>Ready for sampling</span>";
                    break;
                case "4":
                    result = "<span style='color:red'>Not ready for sampling</span>";
                    break;
                case "5":
                    result = "<span style='color:red'>Circulating</span>";
                    break;
                case "6":
                    result = "<span style='color:blue'>Released</span>";
                    break;
                case "7":
                    result = "<span style='color:blue'>Decided</span>";
                    break;
                
                default:
                    result = "<span style='color:red'></span>";
                    break;
            }
            return result;
        }


        //状态显示
        public string ShowStatus(string Status)
        {
            string result = "";
            result = "";

            switch (Status.ToLower())
            {
                case "0":
                    result = "Create new PPAR";
                    break;
                case "1":
                    result = "Edit";
                    break;
                case "2":
                    result = "View";
                    break;
                case "3":
                    result = "Not ready for sampling";
                    break;
                case "4":
                    result = "Edit";
                    break;
                case "5":
                    result = "Circulating";
                    break;
                case "6":
                    result = "Released";
                    break;
                case "7":
                    result = "Decided";
                    break;

                default:
                    result = "View";
                    break;
            }
            return result;
        }

         //状态显示
        public string ShowImage(string Status)
        {
            string result = "";
            result = "image/add.gif";

            switch (Status.ToLower())
            {
                case "0":
                    result = "image/add.gif";
                    result = "../Images/newimg/new.png";
                    break;
                case "1":
                    result = "image/edit.png";
                    result = "../Images/newimg/write.png";
                    break;
                case "2":
                    result = "image/show.gif";
                    result = "../Images/newimg/see.png";
                    break;
                case "3":
                    result = "image/show.gif";
                    result = "../Images/newimg/see.png";
                    break;
                case "4":
                    result = "image/show.gif";
                    result = "../Images/newimg/see.png";
                    break;
                case "5":
                    result = "image/show.gif";
                    result = "../Images/newimg/see.png";
                    break;
                case "6":
                    result = "image/show.gif";
                    result = "../Images/newimg/see.png";
                    break;
                case "7":
                    result = "image/show.gif";
                    result = "../Images/newimg/see.png";
                    break;

                default:
                    result = "image/show.gif";
                    result = "../Images/newimg/see.png";
                    break;
            }
            return result;
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

        }
    }
}